import requests
from bs4 import BeautifulSoup
def findDetail(url):
    #返回的字符串
    returnStr = ""
    # url = 'http://yangzhou.ganji.com//fang2/2454099523x.htm'
    res = requests.get(url)
    res.encoding = 'utf-8'
    html = res.text
    # 解析
    soup = BeautifulSoup(html, 'html.parser')
    # 取时间
    updatetime = soup.select('.title-info-l li .f10')[0].text
    print('发布日期：' + updatetime)
    returnStr=returnStr+'发布日期：' + updatetime + '\n'

    # 取内容  基本信息
    title_content = soup.select('.basic-info')[0]

    # 各个标题的内容
    title = title_content.select('ul li')
    qwzj = title[0]
    print(qwzj.text)
    returnStr = returnStr + qwzj.text +'\n'
    qwhx = title[1]
    print(qwhx.text)
    returnStr = returnStr + qwhx.text + '\n'
    qwxq = title[2]
    print(qwxq.text)
    returnStr = returnStr + qwxq.text + '\n'
    if len(title) > 3:
        qwqy = title[3]
        qwqy_detail = qwqy.select('span')[0].text
        for temp in qwqy.select('a'):
            qwqy_detail = qwqy_detail + "-" + temp.text
        print(qwqy_detail)
        returnStr = returnStr + qwqy_detail + '\n'

    # =====联系方式
    contact = title_content.select('.contact-col')[0]
    name = contact.select('i')[0].text
    person = contact.select('i')[1].text
    print("联系人：" + name + '--' + person)
    returnStr = returnStr + "联系人：" + name + '--' + person + '\n'

    mobile = title_content.select('.contact-mobile')[0].text
    print(mobile)
    returnStr = returnStr + mobile + '\n'

    summary_contont = soup.select('.summary-cont')[0].text
    print('房源描述：' + summary_contont)
    returnStr = returnStr + '房源描述：' + summary_contont + '\n'
    return returnStr

